﻿function selectoperator(operator, sourceid) {
    var src = document.getElementById(sourceid).value;

    if (src == "MainContent_TBGroupBy") {
        if (operator.indexOf('@') > -1) {

        }
        else {
            alert("This field Not allowed in Group by!!!");
            return false;
        }
    }
    
    var source = document.getElementById(src);
    if (source != null) {
        source.value = source.value + operator;
    }

    if (src == "MainContent_txtThenPart" && operator.indexOf('$') == -1 && operator.indexOf('@') > -1) {
        setTableName(operator);
    }

    return false;
}

function selectoperator_sub(operator, sourceid) {
    var src = document.getElementById(sourceid).value;
    //   alert(src);
    var source = document.getElementById(src);
    if (source != null) {
        source.value = source.value + operator;
    }

    return false;
}

function setCurrentControl(sourceControl, destControl) {
    document.getElementById(destControl).value = sourceControl;
    //alert(document.getElementById(destControl).value);
    return false;
}

function setTableName(tblname) {
    var tname = tblname.split('.')[0].replace("@(", "");
    //   alert(tname);
    var tblControl = document.getElementById("MainContent_tableNames");

    if (tblControl.value == "") {
        tblControl.value = tname;
    }
    else {
        if (tblControl.value.indexOf(tname) < 0) {
            tblControl.value += "," + tname;
        }
    }
    // alert(tblControl.value);
}

function validateForm() {
    var c1val = document.getElementById("MainContent_txtFurmulaName").value;
    var c2val = document.getElementById("MainContent_txtThenPart").value;
    var msg = "";
    if (c1val == "") {
        msg += "Please enter the formula name.\n";
    }
    if (c2val == "") {
        msg += "Please enter the Then part.\n";
    }

    if (msg == "") {
        return true;
    }
    else {
        alert(msg);
        return false;
    }
}

function validateForm_Subrule() {
    var tdate = new Date();
    var c1val = document.getElementById("MainContent_txtSubruleName").value;
    var c2val = document.getElementById("MainContent_txtThenPart").value;
    var fromDate = document.getElementById("MainContent_txtFromDate").value;
    var toDate = document.getElementById("MainContent_txtToDate").value;

    var msg = "";

    if (c1val == "") {
        msg += "Please enter the subrule name.\n";
    }
    if (c2val == "") {
        msg += "Please enter the Then part.\n";
    }

    if (fromDate == "") {
        msg += "Please enter the From date.\n";
    }

    if (toDate == "") {
        msg += "Please enter the To date.\n";
    }

    if (fromDate < tdate.getDate()) {
        msg += "From date cannot be less than Today's date";
    }

    if (fromDate > toDate) {
        msg += "From date cannot be greater than To date";
    }

    if (msg == "") {
        return true;
    }
    else {
        alert(msg);
        return false;
    }
}

function validateForm_rejection() {
    var tdate = new Date();
    var c1val = document.getElementById("MainContent_txtFurmulaName").value;
    var c2val = document.getElementById("MainContent_txtWhenPart").value;
    var fromDate = document.getElementById("MainContent_txtFromDate").value;
    var toDate = document.getElementById("MainContent_txtToDate").value;

    var msg = "";
    if (c1val == "") {
        msg += "Please enter the Rejection rule name.\n";
    }
    if (c2val == "") {
        msg += "Please enter the When part.\n";
    }

    if (fromDate == "") {
        msg += "Please enter the From date.\n";
    }

    if (toDate == "") {
        msg += "Please enter the To date.\n";
    }

    if (fromDate < tdate.getDate()) {
        msg += "From date cannot be less than Today's date";
    }

    if (fromDate > toDate) {
        msg += "From date cannot be greater than To date";
    }

    if (msg == "") {
        return true;
    }
    else {
        alert(msg);
        return false;
    }
}

function Validation_Slab() {
    var tdate = new Date();
    var fromDate = document.getElementById("MainContent_TextBoxFrom").value;
    var toDate = document.getElementById("MainContent_TextBoxTo").value;

    var msg = "";

    if (fromDate == "") {
        msg += "Please enter the From date.\n";
    }

    if (toDate == "") {
        msg += "Please enter the To date.\n";
    }

    if (fromDate < tdate.getDate()) {
        msg += "From date cannot be less than Today's date";
    }

    if (fromDate > toDate) {
        msg += "From date cannot be greater than To date";
    }

    if (msg == "") {
        return true;
    }
    else {
        alert(msg);
        return false;
    }
}

function Validation_RuleDefination() {
    var tdate = new Date();
    var fromDate = document.getElementById("MainContent_TBFrom").value;
    var toDate = document.getElementById("MainContent_TBToDate").value;

    var msg = "";

    if (fromDate == "") {
        msg += "Please enter the From date.\n";
    }

    if (toDate == "") {
        msg += "Please enter the To date.\n";
    }

    if (fromDate < tdate.getDate()) {
        msg += "From date cannot be less than Today's date";
    }

    if (fromDate > toDate) {
        msg += "From date cannot be greater than To date";
    }

    if (msg == "") {
        return true;
    }
    else {
        alert(msg);
        return false;
    }
}


function IsExecute() {
    var rid = document.getElementById("MainContent_hf_ruleID").value;

    if (rid) {
        if (confirm("Do you want to execute this rule!"))
            return true;
        else
            return false;
    }
    else {
        alert("Please select Rule.");
        return false;
    }
}
